


# from django.db import models
# from django.contrib.auth.models import AbstractUser

# class CustomUser(AbstractUser):
#     last_activity = models.DateTimeField(null=True, blank=True)
#     activity_count = models.IntegerField(default=0)
    
#     # 移除 Meta 类中的 app_label
    
#     def __str__(self):
#         return self.username



from django.db import models
from django.contrib.auth.models import AbstractUser
from django.utils.translation import gettext_lazy as _

class CustomUser(AbstractUser):
    last_activity = models.DateTimeField(
        null=True, 
        blank=True,
        verbose_name=_("最后活动时间")
    )
    activity_count = models.IntegerField(
        default=0,
        verbose_name=_("活动计数")
    )
    
    class Meta:
        verbose_name = _("自定义用户")
        verbose_name_plural = _("自定义用户")
    
    def __str__(self):
        return self.username
    
    @property
    def activity_level(self):
        """计算用户活动级别"""
        if self.activity_count > 100:
            return "活跃用户"
        elif self.activity_count > 10:
            return "普通用户"
        return "新用户"